﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SES.CMS.DO;
using SES.CMS.BL;

namespace SES.CMS.AdminCP.PageUC
{
    public partial class ucProductCategory : System.Web.UI.UserControl
    {
        cmsLoaiSanPhamDO objLSanPham = new cmsLoaiSanPhamDO();
        protected void Page_Load(object sender, EventArgs e)
        {
            //Functions.ddlDatabinder(drpParentID, cmsLoaiSanPhamDO.LOAISANPHAMID_FIELD, cmsLoaiSanPhamDO.TENLOAISANPHAM_FIELD, new cmsLoaiSanPhamBL().SelectAll(0));
            if (Request.QueryString["PID"] != null)
            {
                objLSanPham.LoaiSanPhamID = int.Parse(Request.QueryString["PID"].ToString());
                InitForm();
            }
        }

        protected void InitForm()
        {
            objLSanPham = new cmsLoaiSanPhamBL().Select(objLSanPham);
            txtTenLSanPham.Text = objLSanPham.TenLoaiSanPham.ToString();
            txtMoTa.Text = objLSanPham.MoTa.ToString();
            //try
            //{
            //    drpParentID.SelectedValue = objLSanPham.ParentID.ToString();
            //}
            //catch
            //{
            //}
        }

        protected void SetObject()
        {
            objLSanPham.TenLoaiSanPham = txtTenLSanPham.Text;
            objLSanPham.MoTa = txtMoTa.Text;
            objLSanPham.ParentID = 0;
        }
        long i;
        protected void btnLuu_Click(object sender, EventArgs e)
        {
            SetObject();
            if (objLSanPham.LoaiSanPhamID <= 0)
            {
                i = new cmsLoaiSanPhamBL().Insert(objLSanPham);
                Functions.Alert("Thêm mới thành công", "Default.aspx?Page=ListProductCategory");
            }
            else
            {
                i = new cmsLoaiSanPhamBL().Update(objLSanPham);
                i = objLSanPham.LoaiSanPhamID;
                Functions.Alert("Cập nhật thành công", "Default.aspx?Page=ListProductCategory");
            }
        }

        protected void btnHuy_Click(object sender, EventArgs e)
        {

        }
    }
}